<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>1.localStorage</title>
    </head>
    <body>
        <button onclick="saveData()">点我存入数据</button>
        <button onclick="readData()">点我读取数据</button>
        <button onclick="updateData()">点我修改数据</button>
        <button onclick="deleteData()">点我删除数据</button>
        <button onclick="deleteAllData()">点我清除数据</button>

        <script type="text/javascript" >
            let person = {name:'大嬷嬷',age:18}
            let person2 = {name:'海峰老师',age:28}

            function saveData(){
                localStorage.setItem('e',JSON.stringify(person))
            }

            function readData(){
                let r1 = localStorage.getItem('a')
                let r2 = localStorage.getItem('b')
                let r3 = localStorage.getItem('c')
                let r4 = localStorage.getItem('d')
                let r5 = localStorage.getItem('e')
                let r6 = localStorage.getItem('age')

                console.log(r1)
                console.log(r2)
                console.log(r3)
                console.log(r4)
                console.log(JSON.parse(r5))
                console.log(JSON.parse(r6))
            }
            
            function updateData(){
                localStorage.setItem('e',JSON.stringify(person2))
            }

            function deleteData(){
                localStorage.removeItem('c')
                localStorage.removeItem('d')
            }

            function deleteAllData(){
                localStorage.clear()
            }
       </script>
    </body>
</html>